<?php
class m_search extends CI_Model{
	
	public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	public function get100($lang){
		$this->load->helper('text');
		$this->db->limit(15);
		$this->db->order_by("ID", "desc");
		$query = $this->db->get($lang);
		$data = array();
		$resut =  $query->result_array();
        foreach($resut as $row){
			$row['MeanWord'] = word_limiter($row['MeanWord'], 10);
			$row['word'] = str_replace('[','',$row['word']);
			$row['word'] = str_replace(']','',$row['word']);
            $data[] = $row;
         }
		 //lay ten hien thi
		$resut = array();
		$resut = $data;
		$query=$this->db->get($lang);
		$CI =& get_instance();
        $this->load->model('auth');
		foreach($resut as $term){
			$a = $CI->auth->get_Name_User($term['userID']);
			$term['userID'] = $a[0]['display_name'];
			$term1[] = $term;
		}
		return $term1;
	}
	
	public function search($wordSearch,$lang){
		$wordSearch = urldecode($wordSearch);
		$this->db->limit(Ket_Qua_Limit_TuDien);
		//$this->db->order_by("ID", "desc"); 
		
		if($lang=="ende"){
			$lang="deen";
			$this->db->where('MeanWord', $wordSearch);
		}else{
			$this->db->where('word', $wordSearch);
		}		
		$query=$this->db->get($lang);
		$resut =  $query->result_array();
		$CI =& get_instance();
        $this->load->model('auth');
		$term1 = array();
		foreach($resut as $term){
			$a = $CI->auth->get_Name_User($term['userID']);
			$term['userID'] = $a[0]['display_name'];
			$term1[] = $term;
		}
		return $term1;
	}
	
	public function getComplete($term,$lang){
		$this->db->limit(7);
		$this->db->select('word');
		$this->db->like('word', $term, 'after');
		$query = $this->db->get($lang);
		$data = array();
        foreach($query->result_array() as $row){
             $data[] = $row['word'];
         }
       return $data;
	}
	
	public function like($wordSearch,$lang){
		if ($wordSearch=="" or $wordSearch=="$1") return null;
		$wordSearch = urldecode($wordSearch);
		$this->db->limit(Ket_Qua_Limit_TuDien);
		if($lang=="ende"){
			$lang="deen";
			$this->db->like('word', ' '.$wordSearch.' ');
		}else{
			$this->db->like('word', ' '.$wordSearch.' ');
		}
		
		$query=$this->db->get($lang);
		return $query->result_array();
	}

}




?>